package com.amit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name="demos",urlPatterns="/demo.jlc",loadOnStartup=1,initParams={@WebInitParam(name="city",value="Blore")})
public class DemoServlet  extends HttpServlet{
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		
		System.out.println("DemoServlet-init()");
		
		String ci=config.getInitParameter("city");
		System.out.println(ci);
		
	}
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		System.out.println("DemoServlet-service()");
		String nm=request.getParameter("name");
		String em=request.getParameter("email");
		String ip=request.getRemoteAddr();
		String msg="<h1>Hello!"+nm+"<br>";
		msg=msg+"your Email Id is"+em;
		msg=msg+"Your are sending the requesting from Ip Address"+ip;
		request.setAttribute("MSG", msg);
		PrintWriter out=response.getWriter();
		out.write(msg);
		
	}
	
	@Override
	public void destroy() {
		
		System.out.println("DemoSrvlet-destroy()");
	}
	

}
